/*pmFWCFu5nhKkBzYmrkBakSV6B6xE5zJS9Xlf9U/PYPi9wdgsReU89OhlkJs/0fgI*/
/*
 * @Author: xiahui 
 * @PageInfo: 采购合同付款计划列表态模板
 * @Date: 2019-02-28 20:25:14 
 * @Last Modified by: raoczh
 * @Last Modified time: 2020-08-24 09:43:22
 */
import { PAGECODE, AREA, FIELDS, UISTATUS, BUTTONID } from '../../constance';
import { setRefMainOrgPermissonByItem } from '../../../pub/utils/referUtil';
import { setPsndocShowLeavePower, setRefShowDisabledData } from '../../../../../scmpub/scmpub/pub/tool/refUtils';
import { buttonControl } from '../viewControl/buttonControl';
import { getListDisableHotKeyBtn } from '../../../../../scmpub/scmpub/pub/tool/hotKeysUtil';
import { buttonClick, searchBtnClick } from '../btnClicks';
import { getLangByResId } from '../../../../../scmpub/scmpub/pub/tool/multiLangUtil';

export default function(props) {
	props.createUIDom(
		{
			pagecode: PAGECODE.listPagecode
		},
		(data) => {
			if (data) {
				if (data.button) {
					let button = data.button;
					props.button.setButtons(button);
				}
				if (data.template) {
					let meta = data.template;
					modifierMeta.call(this, props, meta);
					props.meta.setMeta(meta);
				}
				setDefaultData.call(this, props);
			}
		}
	);
}

function modifierMeta(props, meta) {
	// 添加操作列
	meta[AREA.listTableId].items.push({
		label: getLangByResId(this, '4004PAYPLAN-000005') /* 国际化处理： 操作*/,
		itemtype: 'customer',
		attrcode: 'opr',
		width: '180px',
		visible: true,
		fixed: 'right',
		render: (text, record, index) => {
			if (this.state.status == UISTATUS.edit) {
				let buttonArr = [ BUTTONID.InsertLine, BUTTONID.DeleteLine, BUTTONID.CopyLine ];
				return props.button.createOprationButton(buttonArr, {
					area: AREA.list_inner,
					ignoreHotkeyCode: getListDisableHotKeyBtn(),
					buttonLimit: 3,
					onButtonClick: (props, key) => buttonClick.call(this, props, key, text, record, index)
				});
			}
		}
	});

	searchRefFilter(props, meta, AREA.searchId);
	return meta;
}

// 查询区参照过滤
function searchRefFilter(props, meta, moduleId) {
	meta[moduleId].items.map((item) => {
		// 显示离职人员
		setPsndocShowLeavePower(item);
		// 显示停用
		setRefShowDisabledData(item);

		//主组织过滤
		if (item.attrcode === FIELDS.pk_org) {
			setRefMainOrgPermissonByItem(item);
		} else if (item.attrcode === FIELDS.ctrantypeid) {
			// 合同类型
			item.queryCondition = () => {
				return {
					parentbilltype: 'Z2'
				};
			};
		} else if (item.attrcode === FIELDS.cvendorid) {
			// 供应商
			item.queryCondition = () => {
				let pk_org = (props.search.getSearchValByField(moduleId, FIELDS.pk_org) || {}).value;
				return {
					pk_org: (pk_org || {}).firstvalue
				};
			};
		} else if (item.attrcode === FIELDS.depid) {
			// 采购部门
			item.queryCondition = () => {
				let pk_org = (props.search.getSearchValByField(moduleId, FIELDS.pk_org) || {}).value;
				return {
					pk_org: (pk_org || {}).firstvalue,
					busifuncode: 'pu'
				};
			};
		} else if (item.attrcode === FIELDS.personnelid) {
			// 采购员
			item.isShowUnit = false;
			item.queryCondition = () => {
				let pk_org = (props.search.getSearchValByField(moduleId, FIELDS.pk_org) || {}).value;
				let pk_dept = (props.search.getSearchValByField(moduleId, FIELDS.depid) || {}).value;
				return {
					pk_org: (pk_org || {}).firstvalue,
					pk_dept: (pk_dept || {}).firstvalue,
					busifuncode: 'pu'
				};
			};
		}
	});
}

function setDefaultData(props) {
	let pk_org = props.getUrlParam(FIELDS.pk_org);
	let vbillcode = props.getUrlParam(FIELDS.vbillcode);
	if (pk_org && vbillcode) {
		props.search.setSearchValByField(AREA.searchId, FIELDS.pk_org, JSON.parse(pk_org));
		props.search.setSearchValByField(AREA.searchId, FIELDS.vbillcode, { value: vbillcode });
		searchBtnClick.call(this, props);
	}
	buttonControl.call(this, props, UISTATUS.browse);
	props.button.setButtonDisabled([ BUTTONID.Edit, BUTTONID.Refresh, BUTTONID.Print ], true);
}

/*pmFWCFu5nhKkBzYmrkBakSV6B6xE5zJS9Xlf9U/PYPi9wdgsReU89OhlkJs/0fgI*/